#include <iostream>
#include <fstream>
using namespace std;

int main(void)
{
    char data[100];
    
    //写文件
    ofstream outfile;
    ifstream infile;
    char const *file = "/tmp/user.info";
    outfile.open(file);    
    cout << "Writing to file " << file << endl;
    cout << "Enter Your name: ";
    cin >> data; // scanf("%s", data);
    outfile << data << endl; // fprintf(out, "%s\n", data)
    cout << "Continue write to file " << file << endl;
    cout << "Enter Your age: "; // scanf("%s", data);
    cin >> data; //这里同样存储为字符串 
    outfile << data << endl;
    outfile.close();
    infile.open("/tmp/user.info");
    cout << "Reading data from file " << file << endl;
    infile >> data; //fscanf(in, "%s", data)
    cout << data << endl;
    
    cout << "Continue read data from file " << file << endl;
    infile >> data;
    cout << data << endl;
    infile.close();
    return 0;
}
